<?php
//网站统计
class StatsController extends Controller
{
	//访客统计
	public function actionPage()
	{
		//IP地址
	 	$remote =$_SERVER['REMOTE_ADDR'];
	 	//页面地址
	 	$referer = $_SERVER['HTTP_REFERER'];
	 	//客户端浏览器信息
	 	$user_agent	= $_SERVER['HTTP_USER_AGENT'];
	 	//请求地址
	 	$request	= "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
	 	
	 	
	 	$thisDayStarTime = strtotime(date('y-m-d'));//当天一天开始时间截
	 	$criteria=new CDbCriteria;
	 	$criteria->compare('zhi_ip',$remote);
	 	$criteria->compare('zhi_url',$referer);
	 	$criteria->compare('inputtime','>'.$thisDayStarTime);
	 	$model = Hits::model()->find($criteria);
	 	if(empty($model)){
	 		$model = new Hits();
	 		//正获取产品ID
	 		$preg="/\/product\/detail\/id\/([0-9]+)/";
	 		preg_match_all($preg,$referer,$arr);
	 		if(isset($arr[1][0])&&!empty($arr[1][0])){
	 			$id = $arr[1][0];
	 			$product = Product::model()->findByPk($id);
	 			if(!empty($product)){
	 				$model->zm_id = $product->zm_id;
	 				$model->zp_id = $product->zp_id;
	 			}
	 		}
	 		
	 		$model->zhi_ip = $remote;
	 		$model->inputtime = time();
	 		$model->zhi_hits = 1;
	 		$model->zhi_time = 1;
	 		$model->zhi_day_time = $thisDayStarTime;
	 		$model->zhi_agent = $user_agent;
	 		$model->zhi_url = $referer;
	 		$product-> zp_hits = $product-> zp_hits+1;
	 		$product->Save();
	 	}else{
	 		$model->zhi_hits = $model->zhi_hits + 1;//点数加一
	 		$model->zhi_time = time() - $model->inputtime;//更新页面停留时间
	 	}
	 	$model->save();
	 	
	 	echo "/*流量统计*/";
		exit;
	}
}